package io.gitee.zhangbinhub.acp.core.common.security

import io.gitee.zhangbinhub.acp.core.common.base.BaseEncrypt
import java.security.MessageDigest

/**
 * @since JDK 17
 */
object SignatureEncrypt : BaseEncrypt() {
    internal var MD5 = "MD5"
    internal var SHA1 = "SHA-1"
    internal var SHA256 = "SHA-256"

    /**
     * 加密
     *
     * @param plainText 待加密字符串
     * @param algorithm 使用的算法
     * @return 密文
     */
    @JvmStatic
    @Throws(Exception::class)
    @JvmOverloads
    fun encrypt(
        plainText: String, algorithm: String,
        inputEncode: ByteEncodeEnum = ByteEncodeEnum.BYTE,
        outputEncode: ByteEncodeEnum = ByteEncodeEnum.HEX
    ): String =
        encodeToString(MessageDigest.getInstance(algorithm).digest(decodeToBytes(plainText, inputEncode)), outputEncode)

}
